<template>
  <view class="goods-item" @click="goToDetail(goods.goods_id)">
    <view class="goods-item-left">
      <slot name="radio"></slot>
      <image
        class="goods-pic"
        :src="goods.goods_small_logo || defaultPic"
        mode="scaleToFill"
      />
    </view>
    <view class="goods-item-right">
      <text class="goods-name"> {{ goods.goods_name }} </text>
      <view class="price_number">
        <text class="goods-price">￥{{ goods.goods_price | toFixed }}</text>
        <slot name="number"></slot>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    goods: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      // 默认的空图片
      defaultPic: require("../../static/logo.png"),
    };
  },
  // 过滤器，保持两位小数
  filters: {
    toFixed(val) {
      return val.toFixed(2);
    },
  },
  methods: {
    // 跳转到商品详情页面
    goToDetail(goods_id) {
      uni.navigateTo({
        url: `/subpkg/goods-detail/index?goods_id=${goods_id}`,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.goods-item {
  display: flex;
  padding: 10px 5px;
  border-bottom: 1px solid #f0f0f0;

  .goods-item-left {
    margin-right: 5px;
    display: flex;
    align-items: center;

    .goods-pic {
      width: 100px;
      height: 100px;
      display: block;
    }
  }

  .goods-item-right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    .goods-name {
      font-size: 13px;
    }
    .price_number {
      display: flex;
      align-items: center;
      justify-content: space-between;
      .goods-price {
        font-size: 16px;
        color: #c00000;
      }
    }
  }
}
</style>
